# encoding: utf-8
"""
    测试国内或者国际开机图广告接口特定区域(IP)广告返回
"""
from qa.interface.app.parameters import ia_configure, ia_token, ia_http
import time
import hashlib
class splash():
    def __init__(self, url, users, passwds, is_online):
        # 测试IP
        # 103.238.132.8
        # ip = '103.238.132.8'
        # 请求开机图url
        # self.url = 'https://argo.blued.cn/blued/splash?ip=%s'%ip
        # self.url = 'http://106.75.141.41/blued/splash?conn_type=wifi&exclude_id=0'  #开机图广告
        # self.url = 'http://106.75.141.41/live/hot/banner'  #开机图广告
        self.url = url
        self.users = users
        self.passwds = passwds
        self.is_online = is_online

    def post(self):
        try:
            if self.users == '' and self.passwds == '':
                if self.is_online == 0:
                    self.users = '10@qq.com'
                    self.passwds = '1'
                else:
                    self.users = '2574006368@qq.com'
                    self.passwds = '1234'
            if self.is_online == '0':
                myurl = 'http://106.75.141.41'
            else:
                myurl = 'https://argo.blued.cn'
            mypass = hashlib.sha1(self.passwds).hexdigest()
            res = ia_token.addHeader(1, self.users, mypass, myurl, 1)#主态账号需要鉴权

            if res[0] == 0:
                if res[1] == 401:
                    return "用户名和密码不正确"
                elif res[1] == 4036002:
                    return "因为多次输入错误密码,您需要输入验证码,请用app登录一下该账号再重试"
            auth = eval(ia_token.get_auth(1))
            myhttp = ia_http.py_http()
            page = myhttp.http_read(self.url,auth,ia_configure.t_http,'')
            return page
        except:
            return "鉴权错误,请检查用户名和密码是否输入正确"
# if __name__ == '__main__':
#     url = 'http://106.75.141.41/live/hot/banner'
#     splash = splash(url)
#     message = splash.post()
    # print message
    # count = 0
    # for i in range(100):
    #     message = splash.post()
    #     time.sleep(1)
    #     if message[8:11] == '200':
    #         count += 1
    #         print "通过%s"%count
    #     else:
    #         print message
    # print 'pass %s'%count